package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Calculadora")
public class ServletCalculadora extends HttpServlet {
	private static final long serialVersionUID = 1L;
     
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int valor1 = Integer.parseInt(request.getParameter("valor1")) ;
		int valor2 = Integer.parseInt(request.getParameter("valor2"));
		String operador = request.getParameter("operador");
		float result=0;
		
		switch(operador){
		case "+":
			result= valor1 + valor2;
			break;
		case "-":
			result= valor1 - valor2;
			break;
		case "*":	
			result= valor1 * valor2;
			break;
		case "/":
			result= valor1 / valor2;
			break;
		}
		
		PrintWriter writer = response.getWriter();
		writer.println("<html><head></head><body>");
		writer.println("<h2>"+result);
		writer.println("</h2><hr><a href='Calculadora.html'>volver</a>");
		writer.println("</html></body>");
		writer.close();
		
	}

}
